<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/jquery-1.11.0.js"></script>
</head>
<body>
<div>
    用户名: <input type="text" name="uname" id="uname"> <br>
    密码: <input type="password" name="pwd" id="pwd"> <br>

    <button id="login">登录</button>

    <script>
        $("#login").click(function (){

            let uname = $("#uname").val();
            let pwd = $("#pwd").val();
            let user = {"uname":uname,"pwd":pwd};


            $.ajax({
                url:"/user/login",
                type:"POST",
                data: JSON.stringify(user),
                contentType:"application/json", //设置请求体内容格式
                success:function (r){
                    let code = r.code;
                    if (code == 200){
                        //登录成功 -- 跳转到首页
                        location.href = "index.html"
                    }else{
                        //登录失败 -- 提示用户
                        let msg = r.msg;
                        alert(msg)
                    }
                },
                dataType:"json" //告诉浏览器服务器相应回来的是一个json格式数据
            })
        });
    </script>
</div>
</body>
</html>